package org.bongo.open.cumulo.arbitrator;

import java.io.*;

import org.bongo.open.cumulo.arbitrator.broker.ProcEngineBrokerClient;
import org.bongo.open.cumulo.arbitrator.distribute.HashMessageDistributor;
import org.bongo.open.cumulo.core.context.CumuloContext;
import org.bongo.open.cumulo.core.message.BasicStringMessage;

public class ArbitratorInvoker {

	public static void main(String[] args) throws Exception{
		final String filepath = "/Users/smitha/ProjectWorks/GE2011.11p1/Changelog.SGE";
		
		CumuloContext context = new CumuloContext();
		
		File inputFile = new File(filepath);
		BufferedReader inputFileReader = new BufferedReader(new FileReader(inputFile));
		
		String readLine;
		BasicStringMessage stringMessage = new BasicStringMessage();
		ProcEngineBrokerClient clientBroker = new ProcEngineBrokerClient();
		
		Arbitrator arbitrator = new Arbitrator(clientBroker);
		HashMessageDistributor distributor = new HashMessageDistributor();
		try {

			while((readLine = inputFileReader.readLine() ) != null) {
				stringMessage.setMessageContent(readLine);
				ProcEngineBrokerClient client = arbitrator.getProcEngineBrokerClient(distributor, stringMessage, context);
				client.submitMessage(stringMessage, context);
			}

			clientBroker.shutdown();
		} finally {
			inputFileReader.close();
		}
		
		
		
	}
}
